from sqlalchemy import Column, Integer, String, DateTime, Boolean
from datetime import datetime
from app.database import Base

class Config(Base):
    __tablename__ = "configs"

    id = Column(Integer, primary_key=True, index=True)
    client_type = Column(String(50))
    host = Column(String(255))
    port = Column(Integer)
    username = Column(String(255))
    password = Column(String(255))
    enabled = Column(Boolean, default=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def get_enabled(self) -> bool:
        """获取启用状态"""
        return bool(self.enabled)

class ScanPath(Base):
    __tablename__ = "scan_paths"

    id = Column(Integer, primary_key=True, index=True)
    path = Column(String(500), unique=True, index=True)
    enabled = Column(Boolean, default=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

    def get_path(self) -> str:
        """获取扫描路径字符串"""
        return str(self.path)

class ScanResult(Base):
    __tablename__ = "scan_results"

    id = Column(Integer, primary_key=True, index=True)
    file_path = Column(String(1000))
    file_name = Column(String(500))
    file_size = Column(Integer)
    status = Column(String(50))  # not_seeding, deleted
    action_time = Column(DateTime, nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
